# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# TODO:
# * add installation of new documenation (README.html and documentation/) as real dodoc,
#   currently docs end inside the normal install path (/usr/share/phoronix-test-suite/documentation/)

EGIT_REPO_URI="http://www.phorogit.com/repo/phoronix-test-suite.git"
#default:
EGIT_BRANCH="master"
#EGIT_BRANCH="trondheim-12"
inherit eutils depend.php git

DESCRIPTION="Comprehensive testing and benchmarking platform"
HOMEPAGE="http://phoronix-test-suite.com"
SRC_URI=""

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="get-all-deps"


RDEPEND="dev-lang/php
	sys-process/time
	sys-apps/lsb-release
	get-all-deps? ( app-shells/tcsh
		dev-lang/perl
		dev-libs/libaio
		dev-util/ftjam
		dev-util/git
		dev-util/scons
		media-libs/glew
		media-libs/freeimage
		media-libs/imlib2
		media-libs/jpeg
		>=media-libs/libpng-1.2
		>=media-libs/libsdl-1.2
		media-libs/openal
		media-libs/portaudio
		>=media-libs/sdl-image-1.2
		>=media-libs/sdl-net-1.2
		media-libs/libvorbis
		sys-devel/bison
		sys-devel/flex
		sys-devel/gcc
		sys-libs/zlib
		virtual/glut
		>=virtual/jre-1.5
		=virtual/libstdc++-3.3
		x11-base/xorg-server
		>=x11-libs/gtk+-2
		x11-libs/libXvMC
		x11-libs/libXv ) "

pkg_setup() {
	has_php
	require_php_with_use cli gd pcntl
	if use get-all-deps && ! built_with_use sys-devel/gcc fortran ; then
		echo
		eerror "In order to be able to install all tests for the phoronix-test-suite you need to have"
		eerror "sys-devel/gcc emerged with \"fortran\" in your USE flag. Please add"
		eerror "that flag, re-emerge gcc, and then emerge phoronix-test-suite again."
		echo
		die "sys-devel/gcc not built with \"fortran\" support."
	fi
	if use get-all-deps && use amd64 && ! built_with_use sys-devel/gcc multilib ; then
		echo
		eerror "In order to be able to install all tests for the phoronix-test-suite you need to have"
		eerror "sys-devel/gcc emerged with \"multilib\" in your USE flag. Please add"
		eerror "that flag, re-emerge gcc, and then emerge phoronix-test-suite again."
		echo
		die "sys-devel/gcc not built with \"multilib\" support."
	fi
}

src_unpack() {
	git_src_unpack
	cd ${S}
	sed -i -e "s,export PTS_DIR=\`pwd\`,export PTS_DIR=\"/usr/share/${PN}\"," ${PN}
}

src_install() {
	dodir /usr/share/${PN}
	insinto /usr/share/${PN}
	exeinto /usr/bin
	doins -r ${S}/{documentation,pts,pts-core,README.html} || die "Install failed!"
	fperms 755 /usr/share/${PN}/pts-core/scripts/launch-browser.sh
	fperms 755 /usr/share/${PN}/pts/distro-scripts/*.sh
	doexe phoronix-test-suite || die "Installing the executable failed!"
	dodoc CHANGE-LOG
}

pkg_postinst() {
	if ! use get-all-deps ; then
		elog "For several tests external dependencies are needed. You can"
		elog "easily install them with setting the useflag 'get-all-deps'."
		elog "When not having the deps installed, the testsuite will ask for"
		elog "the root password when installing tests that require external"
		elog "dependencies and install them systemwide via portage."
		elog "These are the possible deps:"
		elog "app-shells/tcsh"
		elog "dev-lang/perl"
		elog "dev-libs/libaio"
		elog "dev-util/ftjam"
		elog "dev-util/git"
		elog "dev-util/scons"
		elog "media-libs/glew"
		elog "media-libs/freeimage, due to problems with this package you will have to get the ebuild from bugreport #213969 and manually unmask the build"
		elog "media-libs/imlib2"
		elog "media-libs/jpeg"
		elog ">=media-libs/libpng-1.2"
		elog ">=media-libs/libsdl-1.2"
		elog "media-libs/openal"
		elog "media-libs/portaudio"
		elog ">=media-libs/sdl-image-1.2"
		elog ">=media-libs/sdl-net-1.2"
		elog "media-libs/libvorbis"
		elog "sys-devel/bison"
		elog "sys-devel/flex"
		if use amd64 ; then
			elog "sys-devel/gcc with fortran and multilib useflag active"
		else
			elog "sys-devel/gcc with fortran useflag active"
		fi
		elog "virtual/glut"
		elog ">=virtual/jre-1.5"
		elog "=virtual/libstdc++-3.3"
		elog "x11-base/xorg-server"
		elog ">=x11-libs/gtk+-2"
		elog "x11-libs/libXvMC"
		elog "x11-libs/libXv"
	fi
}

